home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / ObjFloat.C < prev    next >
C/C++ Source or Header  |  1992-05-05  |  971b  |  60 lines

  1. #ifdef __GNUG__
  2. #pragma implementation
  3. #endif
  4.  
  5. #include "ObjFloat.h"
  6.  
  7. #include "Class.h"
  8. #include "String.h"
  9.  
  10. NewMetaImpl(ObjFloat,Object, (T(val)));
  11.  
  12. //---- a float object ----------------------------------------------------------
  13.  
  14. // hashing idea stolen from OOPS
  15.  
  16. static union {
  17.     unsigned long aslong[2];
  18.     double asdouble;
  19. } hashunion;
  20.  
  21.  
  22. u_long ObjFloat::Hash()
  23. {
  24.     hashunion.asdouble= val;
  25.     return hashunion.aslong[0] ^ hashunion.aslong[1];
  26. }
  27.  
  28. bool ObjFloat::IsEqual(Object* op)
  29. {
  30.     return (bool) (op->IsKindOf(ObjFloat) && val == ((ObjFloat*)op)->val);
  31. }
  32.  
  33. int ObjFloat::Compare(Object* op)
  34. {
  35.     double t = val - Guard(op, ObjFloat)->val;
  36.     if (t < 0) 
  37.     return -1;
  38.     if (t > 0)
  39.     return 1;
  40.     return 0;
  41. }
  42.  
  43. char* ObjFloat::AsString()
  44. {
  45.     return form("%g", val);
  46. }
  47.  
  48. OStream& ObjFloat::PrintOn(OStream &s)
  49. {
  50.     Object::PrintOn(s);
  51.     return s << val SP;
  52. }
  53.  
  54. IStream& ObjFloat::ReadFrom(IStream &s)
  55. {
  56.     Object::ReadFrom(s);
  57.     return s >> val;
  58. }
  59.  
  60.